<div class="list-menu" style=" height: 30px;">
  <div class="search">
    <a href="{:U(MODULE_NAME.'/Product/sellrecommendadd')}" class="button-green" style="color:#fff;">推荐产品添加</a>
    <a href="{:U(MODULE_NAME.'/Product/sellrecommendcategorylist')}" class="button-green" style="color:#fff;">推荐分类列表</a>
    <input type="text" name="keyword" class="input-m" value="{$keyword}" id="keyword" placeholder="请输入产品ID或者名称">
    <input type="button" class="button-green" value="查  询" onClick="Request()">
  </div>
</div>
<div>
<table class="list">
		<thead>
  		<tr>
        <th>产品ID</th>
        <th>产品名称</th> 
        <th>分类</th>
        <th>推荐描述</th>
        <th>操作</th>
      </tr>
		</thead>
  <tbody>
		<foreach name='list' item='v'>
        <tr>
           <td class="ProductID" >{$v.productID}</td>
           <td class="title" >{$v.title}</td>
           <td class="categoryName" >{$v.categoryName}</td>
           <td class="description" >{$v.description}</td>
           <td>
               <a href="javascript:;" onclick="edit(this,'{$v.id}')">编辑</a>&nbsp;&nbsp;
               <a href="javascript:;" onclick="toConfirm('{:U(MODULE_NAME.'/Product/sellrecommenddel',array('id' => $v['id']), '')}', '确实要删除吗？')">删除</a>
           </td>
       </tr>
      </foreach>
 </tbody>
</table>
</div>
<div class="page" style="clear: both;">{$page}</div>
<script type="text/javascript">
/**
 * [edit description]产品修改
 * @param  {[type]} obj [description]
 * @return {[type]}     [description]
 */
  function edit (obj,id) 
  {  
    $(obj).parent().parent().find('.ProductID').html('<input type="text" onkeyup="productData(this)" >');
    $(obj).parent().parent().find('.title').html('<input type="text" class="title">');
    $(obj).parent().parent().find('.categoryName').html('<input type="text">');
    $(obj).parent().parent().find('.description').html('<input type="text">');
    $(obj).parent().html('<input type="button" class="button-green" onclick="preserve(this,'+id+')" value="保存"><input type="button" class="button-return" onclick="location.reload()" value="取消">');
  }
  /**
   * [preserve description]
   * @return {[type]} [description]
   */
  function preserve(obj,id)
  { 
    var productID    = $(obj).parent().parent().find('.ProductID input').val();
    var categoryName = $(obj).parent().parent().find('.categoryName input').val();
    var description  = $(obj).parent().parent().find('.description input').val();
    $.ajax({
      url: '{:U(MODULE_NAME.'/Product/sellrecommendedit')}',
      type: 'post',
      dataType: 'json',
      data: {'id':id, 'productID': productID, 'categoryName':categoryName ,'description':description},
      success:function (data) 
      { 
        if(data.msg == 1)
        {
          location.reload();
        }
        else
        {
          alert(data.msg);
        }
      }
    })
    
  }
    /**
   * [function_name description]
   * @param  {[type]} argument [description]
   * @return {[type]}          [description]
   */
  function productData(obj) 
  {
    var id = $(obj).val();
    $.ajax({
      url: '{:U(MODULE_NAME.'/Product/productData')}',
      type: 'post',
      dataType: 'json',
      data: {'id': id},
      success:function (data) 
      { 
        if(data.msg == 1)
        { 
          $(obj).parent().parent().find('.title').val(data.title);
        }
      }
    })
    
  }
</script>